﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using br.com.SistemaChamados.QueryManager.Core;

namespace br.com.SistemaChamados.QueryManager.ReaderParser
{
    public class DataConverter
    {
        public static object bindData(IDataReader aReader, int fieldPosition, Type fieldType)
        {
            object dataToBind = aReader[fieldPosition];
            //Executing convert data
            string describeTypeField = fieldType.FullName;
            switch (describeTypeField)
            {
                case QueryManagerConstants.INTEGER_PARSE:
                    return Convert.ToInt32(dataToBind);
                case QueryManagerConstants.STRING_PARSE:
                    return dataToBind.ToString();
                case QueryManagerConstants.DOUBLE_PARSE:
                    return Convert.ToDouble(dataToBind);
                case QueryManagerConstants.DECIMAL_PARSE:
                    return Convert.ToDecimal(dataToBind);
                case QueryManagerConstants.BOOLEAN_PARSE:
                    bool result = Convert.ToBoolean(dataToBind);
                    return result;
                case QueryManagerConstants.DATETIME_PARSE:
                    return Convert.ToDateTime(dataToBind);
                default:
                    throw new Exception("Unsupported type parser! ["+fieldType.FullName+"]");
            }
        }

    }
}